<template>
    <div>
        <h1>房间添加</h1>
    
<table class="table table-bordered">
    <tr >
        <td align="right">房间名称</td>
        <td><input type="text" v-model="state.hName"></td>
    </tr>
    <tr >
        <td align="right">门市价</td>
        <td><input type="text" v-model="state.money"></td>
    </tr>
    <tr >
        <td align="right">押金</td>
        <td><input type="text" v-model="state.yaJin"></td>
    </tr>
    <tr >
        <td align="right">房型面积</td>
        <td><input type="text" v-model="state.mianJi"></td>
    </tr>
    <tr >
        <td align="right">可住人数</td>
        <td><input type="text" v-model="state.people"></td>
    </tr>
    <tr >
        <td align="right">是否加床</td>
        <td><input type="text" v-model="state.boor"></td>
    </tr>
    <tr >
        <td align="right">介绍</td>
        <td><input type="text" v-model="state.ramite"></td>
    </tr>
    <tr >
        <td></td>
        <td><input type="button" value="登录" @click="add"></td>
    </tr>
</table>
    </div>
</template>

<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter()
let data=reactive({
    state:{
        hName:'',
        money:'',
        yaJin:'',
        mianJi:'',
        people:'',
        boor:'',
        ramite:''
    }
})
let {state}=toRefs(data)
const add=()=>{
    if(state.value.hName==""){
        alert("房间名称不能为空")
        return;
    }
    if(state.value.money==""){
        alert("门市价不能为空")
        return;
    }
    if(state.value.yaJin==""){
        alert("押金不能为空")
        return;
    }
    if(state.value.mianJi==""){
        alert("房型面积不能为空")
        return;
    }
    if(state.value.people==""){
        alert("可住人数不能为空")
        return;
    }
    if(state.value.boor==""){
        alert("是否加床不能为空")
        return;
    }
    if(state.value.ramite==""){
        alert("介绍不能为空")
        return;
    }

    let obj={
        id: 0,
        hName:state.value.hName,
        money:state.value.money,
        yaJin:state.value.yaJin,
        mianJi:state.value.mianJi,
        people:state.value.people,
        boor:state.value.boor,
        ramite:state.value.ramite,
        isDelete: false
    }
    axios({
        url:'/api/House/AddHouse',
        method:'post',
        data:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data==1){
alert("登录成功")
router.push('/houselist')
        }
        else{
            alert("登录失败")
            return;
        }
    })
    .catch(err=>{
        console.log(err)
    })
}
</script>

<style scoped>

</style>